package zhongbo.java.air.dictionary.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.AirPort;
import zhongbo.java.air.dictionary.service.IAirPortService;


@RestController
@RequestMapping("airPort")
@Api(tags = "机场信息相关接口")
public class AirPortController {
    @Autowired
    private IAirPortService iAirPortService;

    @GetMapping("findPage")
    @ApiOperation("分页查询")
    public ResultVo<PageVo<AirPort>> page(Integer page, Integer pageSize
            , String keyword, String fields
            , String oderByField, Boolean orderByAsc){
        return ResultVo.ok(iAirPortService.pageQuery(page, pageSize, keyword, fields, oderByField, orderByAsc));
    }

    @PostMapping("add")
    @ApiOperation("添加机场信息")
    public ResultVo saveAirCraft(@RequestBody AirPort entity){
        return iAirPortService.saveAirPort(entity);
    }

    @DeleteMapping("delete")
    @ApiOperation("删除机场信息")
    public ResultVo deleteAirCraft(String entityId){
        if (!iAirPortService.removeById(entityId)){
            return ResultVo.error("删除失败");
        }
        return ResultVo.ok("删除id:" + entityId);
    }

    @PutMapping("edit")
    @ApiOperation("修改机场信息")
    public ResultVo updateAirCraft(@RequestBody AirPort edit){
        return iAirPortService.updateAirPort(edit);
    }

    @GetMapping("findOne")
    @ApiOperation("查询一条")
    public ResultVo<AirPort> findOne(String entityId){
        return ResultVo.ok(iAirPortService.getById(entityId));
    }
}
